import * as XLSX from "xlsx";

const exports = async () => {
    const doc = new jsPDF();
    // 获取表体数据
    const items = await this.getItems()
    // 创建一个包含数据的工作簿
    const newDate = moment(this.info.date).format("YYYY年MM月");
    const workbook = XLSX.utils.book_new();
    const dataKeys = [
        "合同状态",
        "合同审批编号",
        "客户单位名称",
        "客户负责人",
        "客户负责人电话",
        "我方单位",
        "业务类型",
        "合同总金额",
        "费用",
        "有效金额",
        "提成比例",
        "提成金额",
        "合同成交日期",
        "合同收款日期",
        "备注"
    ];

    const dataValue = items.map(m => {
        return {
            status: m.contract_status_name,
            no: m.contract_no,
            contract_customer_company_name: m.contract_customer_company_name,
            contract_customer_name: m.contract_customer_name,
            contract_customer_phone: m.contract_customer_phone,
            contract_company_name: m.contract_company_name,
            contract_business_type: m.contract_business_type,
            contract_total_money: parseFloat(m.contract_total_money).toFixed(2),
            cost: parseFloat(m.cost).toFixed(2),
            valid_money: parseFloat(m.valid_money).toFixed(2),
            rate: m.rate + '%',
            total_money: parseFloat(m.total_money).toFixed(2),
            contract_deal_date: m.contract_deal_date,
            contract_receive_date: m.contract_receive_date,
            remark: m.remark,
        }
    })
    const dataValues = dataValue.map(item => Object.values(item))
    // 将dataKeys和dataValues组合成一个二维数组
    const dataExcel = [dataKeys, ...dataValues];

    const worksheet = XLSX.utils.aoa_to_sheet(dataExcel);

    // 将工作表添加到工作簿中
    XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");

    // 将工作簿导出为 Excel 文件
    XLSX.writeFile(workbook, `${this.info.employee_name}${newDate}提成单.xlsx`);

}